<?php		
/**
 * 注：此模板为自动生成模板，需要根据实际情况调整修改
 * 此模板对 无主键/单一主键 表的支持较好，联合主键表在下一版本开发
 */					
class Rrn_admin_user {
			
		    //数组	
			private $array;
			
					
			public function Rrn_admin_user($array){	
									  
						$this->array = $array;
				
						 self::setDefault();
				
			   }
		   
		   	
			private function setDefault(){
				
                 if(count($this->array)==0){
				    self::setId("");
					self::setName("");
					self::setPassword("");
					self::setRank("");
					self::setPage("");
					self::setIntro("");
					self::setState("");
					self::setCreatedate("");
					self::setUpdatedate("");
					
							}
					}
				
			
		   				
			
					
				
			public function setId($value) {
			       $this->array = array_merge ($this->array,array(
			       'id' => $value));
		     	} 
			public function getId(){							
			      return $this->array ['id'];
	            } 
					
				
			public function setName($value) {
			       $this->array = array_merge ($this->array,array(
			       'name' => $value));
		     	} 
			public function getName(){							
			      return $this->array ['name'];
	            } 
					
				
			public function setPassword($value) {
			       $this->array = array_merge ($this->array,array(
			       'password' => $value));
		     	} 
			public function getPassword(){							
			      return $this->array ['password'];
	            } 
					
				
			public function setRank($value) {
			       $this->array = array_merge ($this->array,array(
			       'rank' => $value));
		     	} 
			public function getRank(){							
			      return $this->array ['rank'];
	            } 
					
				
			public function setPage($value) {
			       $this->array = array_merge ($this->array,array(
			       'page' => $value));
		     	} 
			public function getPage(){							
			      return $this->array ['page'];
	            } 
					
				
			public function setIntro($value) {
			       $this->array = array_merge ($this->array,array(
			       'intro' => $value));
		     	} 
			public function getIntro(){							
			      return $this->array ['intro'];
	            } 
					
				
			public function setState($value) {
			       $this->array = array_merge ($this->array,array(
			       'state' => $value));
		     	} 
			public function getState(){							
			      return $this->array ['state'];
	            } 
					
				
			public function setCreatedate($value) {
			       $this->array = array_merge ($this->array,array(
			       'createdate' => $value));
		     	} 
			public function getCreatedate(){							
			      return $this->array ['createdate'];
	            } 
					
				
			public function setUpdatedate($value) {
			       $this->array = array_merge ($this->array,array(
			       'updatedate' => $value));
		     	} 
			public function getUpdatedate(){							
			      return $this->array ['updatedate'];
	            } 
		
			
			public function toInsertCSV() {
						 $str="";
				
						// id
						$str .= "'". self::getId()."',";
						// name
						$str .= "'". self::getName()."',";
						// password
						$str .= "'". self::getPassword()."',";
						// rank
						$str .= "'". self::getRank()."',";
						// page
						$str .= "'". self::getPage()."',";
						// intro
						$str .= "'". self::getIntro()."',";
						// state
						$str .= "'". self::getState()."',";
						// createdate
						$str .= "now()" . ",";
						
						// updatedate
						$str .= "now()";
						return $str;
						}
				
		
			
			public function toUpdateSet() {
						 $str="";
				
						// name
						$str.= 'name = "' . self::getName() . '",';
						
						// password
						$str.= 'password = "' . self::getPassword() . '",';
						
						// rank
						$str.= 'rank = "' . self::getRank() . '",';
						
						// page
						$str.= 'page = "' . self::getPage() . '",';
						
						// intro
						$str.= 'intro = "' . self::getIntro() . '",';
						
						// state
						$str.= 'state = "' . self::getState() . '",';
						
						// updatedate
						$str .= "updatedate = now()";
						return $str;
			    }
				
		
			
			public function toUpdateWhere(){
						 $str = ""; 
						$str .= "id = '" . self::getId()."'";
						 return $str;
		        }
		
}		
									
  	
class Rrn_admin_user_DAO {	
									
                private static $TABLENAME = 'RRN_ADMIN_USER';
								
								
			

				public static function getRecord($id,$dbCon){
						 $where = "id = '$id'";
								 $record = SearchDb::getRecord
								 ($dbCon,static::$TABLENAME,$where);
								 if($record != null){
								 return new Rrn_admin_user($record);
				      		}
				      		 return null;
				      		 }
		
			
			
				public static function getList($dbCon) {
						 $where = "";
						 $list = SearchDb::getList($dbCon,static::$TABLENAME,$where);
						 $results = array();
						 
						foreach($list as $record){
						 array_push ( $results, new Rrn_admin_user($record));
								}
								 return $results;
	               }


                public static function getListByNeedle($needle,$dbCon) {
                    $where = "id like '%$needle%' OR name like '%$needle%' ";
                    $list = SearchDb::getList($dbCon,static::$TABLENAME,$where);
                    $results = array();

                    foreach($list as $record){
                        array_push ( $results, new Rrn_admin_user($record));
                    }
                    return $results;
                }

			
			
			   public static function getRecordMem($id,$mstCon,$memCon) {
						 
						$listAll = self::getListMem ( $mstCon,$memCon);
						 
						foreach($listAll as $record) {
						
						if($record->getId() == $id){
								
								return $record;
								
								}
								}
								 return null;
								}

			
			
			   public static function getListMem($mstCon,$memCon){
						 
						$listAll = SearchDb::getListMem($mstCon,$memCon,static::$TABLENAME);
						 
						$results = array();
						 
						foreach($listAll as $record){
						 array_push ( $results,new Rrn_admin_user($record));
								 
					}
								 return $results; 
								 }

			
			
			   public static function insert($record,$dbCon){
				
						try {
					
								$id = $record->getId();
								$oldrecord = self::getRecord($id,$dbCon);
								if($oldrecord != null) {
								   throw new Exception ("重复插入");
								}
								ChangeDb::insert($dbCon,static::$TABLENAME,$record);
							} catch(Exception $e){
								throw $e;
								}
						}

			
			
			   public static function update($record ,$dbCon){
						try{
								$id = $record->getId();
								$oldrecord = self::getRecord($id,$dbCon);
								if($oldrecord == null){
										throw new Exception("不存在该记录");
								}
								ChangeDb::update($dbCon,static::$TABLENAME,$record);
						} catch(Exception $e){
										throw $e;
									}
					 }

			
			
			   public static function delete ($record,$dbCon){
						try{
							$id = $record->getId();
							$oldrecord = self::getRecord($id,$dbCon);
							if($oldrecord == null){
									throw new Exception("不存在该记录");
							}
							ChangeDb::delete($dbCon,static::$TABLENAME,$record);
						} catch(Exception $e){
									throw $e;
				        	}
					}
}
										 
?>